/*
 * @(#) LoginServiceImpl.java 2011-9-7
 *
 * Copyright (c) 2011, Strong Technology. All Rights Reserved.
 * Strong Technology. CONFIDENTIAL
 */
package cn.strong.gweva.common.business.service.impl;

import java.util.Date;

import cn.strong.gweva.common.business.entity.LoginEntity;
import cn.strong.gweva.common.business.entity.UserPwdEntity;
import cn.strong.gweva.common.business.entity.db.JxkhUserEntity;
import cn.strong.gweva.common.business.service.LoginService;
import cn.strong.gweva.common.util.Constants4Method;

/**
 * 登录
 * 
 * @author lilanfei
 * @version 1.0
 * @since 2011-9-7
 */
public class LoginServiceImpl extends AbstractServiceImpl implements LoginService
{
	
	/**
	 * 校验用户名、密码是否正确
	 * @param inputUser
	 * @return
	 * @throws Exception
	 */
	public int checkLoginUser(JxkhUserEntity inputUser) throws Exception
	{
		return this.getCommonDao().searchCount(
				Constants4Method.LOGIN_CHECK_LOGIN_USER, inputUser);
	}

	/**
	 * 根据用户名，检索登录用户信息。
	 * 
	 * @param userName 用户名
	 * @param ip IP
	 * @return 登录用户信息
	 */
	public LoginEntity doLogin(String userName, String ip) throws Exception
	{
		LoginEntity loginUser = (LoginEntity)this.getCommonDao().searchObj(
				Constants4Method.LOGIN_SEARCH_LOGIN_USER_BY_USERNAME, userName);
		
		loginUser.setLoginIp(ip);
		loginUser.setLoginTime(new Date());
		
		this.getCommonDao().update(Constants4Method.LOGIN_UPDATE_USER_LOGIN_INFO, loginUser);
		
		return loginUser;
	}
	
	/**
	 * 校验用户旧密码
	 * 
	 * @param userPwd 用户密码
	 * @return
	 * @throws Exception
	 */
	public int checkOldPwd(UserPwdEntity userPwd) throws Exception
	{
		return this.getCommonDao().searchCount(Constants4Method.LOGIN_CHECK_OLD_PWD, userPwd);
	}
	
	/**
	 * 修改密码
	 * 
	 * @param userPwd 用户密码
	 * @return
	 * @throws Exception
	 */
	public int changePwd(UserPwdEntity userPwd) throws Exception
	{
		return this.getCommonDao().update(Constants4Method.LOGIN_CHANGE_PWD, userPwd);
	}

}
